package cn.cvs.service.impl;

import cn.cvs.dao.SysRoleMapper;
import cn.cvs.pojo.SysRole;
import cn.cvs.service.SysRoleService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Resource
    SysRoleMapper sysRoleMapper;

    @Resource
    RedisTemplate<Object,Object> redisTemplate;

    @Override
    public List<SysRole> queryAllRoles() {
        Object queryAllRoles = redisTemplate.opsForValue().get("queryAllRoles");
        if(queryAllRoles!=null){
            return (List<SysRole>)queryAllRoles;
        }
        List<SysRole> sysRoles = sysRoleMapper.queryAll();
        if(sysRoles!=null){
            redisTemplate.opsForValue().set("queryAllRoles", sysRoles);
        }
        return sysRoles;
    }
    @Override
    public int addRole(SysRole sysRole) {
        int i = sysRoleMapper.addRole(sysRole);
        return i;
    }

    @Override
    public SysRole findSysRoleBycode(String code) {
        return sysRoleMapper.findSysRoleBycode(code);
    }

    @Override
    public int updateRole(SysRole sysRole) {
        int i = sysRoleMapper.updateRole(sysRole);
        return i;
    }

    @Override
    public SysRole queryById(Integer id) {
        SysRole sysRole = sysRoleMapper.queryById(id);
        return sysRole;
    }

    @Override
    public int queryRoleCount(String code) {
        return sysRoleMapper.queryRoleCount(code);
    }

    @Override
    public int delete(int id) {
        return sysRoleMapper.delete(id);
    }
}
